package com.koocloud.electroplatemanage.controller;

import com.koocloud.electroplatemanage.common.pojo.ResponseTemplate;
import com.koocloud.electroplatemanage.pojo.DrawNoVo;
import com.koocloud.electroplatemanage.pojo.PersonVo;
import com.koocloud.electroplatemanage.service.PersonService;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: electroplatemanage
 * @description: 人员控制类
 * @author: zww
 * @create: 2020-09-29 16:25
 */
@RestController
@RequestMapping("/person")
public class PersonController {
    static Logger log = Logger.getLogger("person");
    @Autowired
    PersonService personService;

    /**
     * @Description:通过pk查询人员表一条记录
     * @Param: [pk]
     * @return: com.koocloud.electroplatemanage.common.ResponseTemplate
     * @Author: zww
     * @date: 2020/9/30
     */
    @RequestMapping(value = "/selectByPk", method = RequestMethod.POST, name = "主键查询")
    public ResponseTemplate selectByPk(@RequestParam(name="pkPerson") String pk) {
        //通过pk查询人员表的一条记录
        return personService.selectByPk(pk);
    }

    /**
     * @Description: 查询所有记录 分页  姓名
     * @Param: [page,limit,name]
     * @return: com.koocloud.electroplatemanage.common.ResponseTemplate
     * @Author: zww
     * @date: 2020/9/30
     */
    @RequestMapping(value = "/selectAllData", method = RequestMethod.POST, name = "全表查询")
    public ResponseTemplate selectAllData(String page, String limit,PersonVo personVo) {
        //分页参数为空则赋值0
        if (!StringUtils.isNotEmpty(page)) {
            page = "0";
        }
        if (!StringUtils.isNotEmpty(limit)) {
            limit = "0";
        }
        //查询所有记录 分页
        return personService.selectAllData(page,limit,personVo);
    }

    /**
     *@Description: 校验填写的人员表主键
     *@Param: [drawNoVo]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/10/16
     */
    @RequestMapping(value = "/check", method = RequestMethod.POST, name = "校验填写的人员表主键")
    public ResponseTemplate check(@RequestBody PersonVo personVo) {
        //校验填写的分配工作表主键
        return personService.check(personVo);

    }
    /**
     *@Description:插入一条记录
     *@Param: [personVo]
     *@return: com.koocloud.electroplatemanage.common.ResponseTemplate
     *@Author: zww
     *@date: 2020/9/30
     */
    @RequestMapping(value = "/insert", method = RequestMethod.POST, name = "新增一条数据")
    public ResponseTemplate insert(@RequestBody PersonVo personVo) {
        //插入一条记录
        return personService.insert(personVo);
    }
    /**
     *@Description:批量插入记录
     *@Param: [listPersonVo]
     *@return: com.koocloud.electroplatemanage.common.ResponseTemplate
     *@Author: zww
     *@date: 2020/9/30
     */
    @RequestMapping(value = "/batchInsert", method = RequestMethod.POST, name = "批量新增数据")
    public ResponseTemplate batchInsert(@RequestBody List<PersonVo> listPersonVo) {
        //批量插入记录
        return personService.batchInsert(listPersonVo);
    }
    /**
     *@Description:逻辑删除一条记录
     *@Param: [pk]
     *@return: com.koocloud.electroplatemanage.common.ResponseTemplate
     *@Author: zww
     *@date: 2020/9/30
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST, name = "逻辑删除一条记录")
    public ResponseTemplate delete(@RequestParam(name="pkPerson") String pk) {
        //逻辑删除一条记录
        return personService.delete(pk);
    }
    /**
     *@Description:通过pks批量逻辑删除记录
     *@Param: [listPks]
     *@return: com.koocloud.electroplatemanage.common.ResponseTemplate
     *@Author: zww
     *@date: 2020/9/30
     */
    @RequestMapping(value = "/batchDeleteByPks", method = RequestMethod.POST, name = "批量逻辑删除记录")
    public ResponseTemplate batchDeleteByPks(@RequestBody List<String> listPks) {
        //通过pks批量逻辑删除记录
        return personService.batchDeleteByPks(listPks);
    }
    /**
     *@Description:修改一条记录
     *@Param: [personVo]
     *@return: com.koocloud.electroplatemanage.common.ResponseTemplate
     *@Author: zww
     *@date: 2020/9/30
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST, name = "修改一条记录")
    public ResponseTemplate update(@RequestBody PersonVo personVo) {
        //修改一条记录
        return personService.update(personVo);
    }
}